// pages/my/my_wallet/my_wallet.js
var moneyList = ""; //充值金额数据加载
var indexNumber = ""; //选中的充值金额数据下标
Page({

  /**
   * 页面的初始数据
   */
  data: {
    datasList:[
		{ id: 1,money: "6", heardCoin: "6",activity:""},
		{ id: 2,money: "20", heardCoin: "20", activity: "" },
		{ id: 3,money: "36", heardCoin: "36", activity: "" },
		{ id: 4,money: "336", heardCoin: "336", activity: "" },
		{ id: 5,money: "3336", heardCoin: "3336", activity: "" },
		{ id: 6,money: "26", heardCoin: "26", activity: "" },
		{ id: 7,money: "226", heardCoin: "226", activity: "" },
		{ id: 8,money: "116", heardCoin: "116", activity: "" },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      that.setData({
          moneyList: that.data.datasList
      })
  },

  clickCommentText: function (e) {
      var that = this;
	  indexNumber = e.currentTarget.dataset.number;
      that.setData({
		  indexNumber: indexNumber
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  /**
   * 立即支付按钮触发
   */
	nowPay:function(e){
		indexNumber = this.data.indexNumber //获取选中的数据下标
		console.log(indexNumber)
		if (indexNumber == undefined) {
			wx.showToast({
				title: '请选择您要充值的金额',
				icon: 'none',
				duration: 2000
			})
			return;
		}
		moneyList = this.data.moneyList; //获取加载的数据列表
		var id = moneyList[indexNumber].id //得到选中的id
		var money = moneyList[indexNumber].money//得到充值金额
		console.log("选中了编号："+id+"==金额："+money+"元")
		//业务TODO。。。。。。。。。。


		wx.requestPayment({
			'timeStamp': '1111111',
			'nonceStr': '2222222',
			'package': '333333',
			'signType': 'MD5',
			'paySign': '',
			'success': function (res) {
				wx.showToast({
					title: '支付成功',
					icon: 'none',
					duration: 2000
				})
			},
			'fail': function (res) {
				wx.showToast({
					title: '支付失败',
					icon: 'none',
					duration: 2000
				})
			}
		})

	}

})